<?php
/**
 * Created by openXtiger.org.
 * User: xtiger
 * Date: 2009-6-20
 * Time: 11:43:44
 */
function icweb_categorymodel_getTree($bid=0) {
    return icweb__getTree()->getTree($bid,TRUE);
}
function icweb_categorymodel_getChildTree($bid=0) {
    return icweb__getTree()->getTree($bid,FALSE);
}
function icweb_categorymodel_loadNodeById($bid) {
    return icweb__getTree()->loadNodeById($bid);
}

function icweb_categorymodel_insertNode($bid,$name) {
    if($id = icweb__getTree()->insertNode($bid)>0) {
        $db = xt_load('db','icweb');
        $db->query('INSERT INTO '.xt_tname('category','icweb')." SET pid=$bid, tree_id=$id,name='$name'");
        return TRUE;
    }
    return FALSE;
}
function icweb_categorymodel_retrievePath($bid,$sp='/') {
    return icweb__getTree()->retrievePath($bid,$sp);
}


function icweb_categorymodel_removeNode($bid) {
    $r = icweb__getTree()->removeNode($bid);
    if($r==1) {
        $db = xt_load('db','icweb');
        $db->query('DELETE FROM '.xt_tname('category','icweb')." WHERE id=$bid");
        return TRUE;
    }
    return $r;
}
function icweb__getTree() {
    global $_UC; 
    if(empty($_UC['_icweb_'])){
        $ctree = xt_load('library','tree');
        return $_UC['_icweb_'] = new $ctree(xt_load('db','icweb'),xt_tname('tree','icweb'),xt_tname('category','icweb'));
    }
    return $_UC['_icweb_'];
}
?>